home *** CD-ROM | disk | FTP | other *** search
-
- #include <MacHeaders>
- #include <Files.h>
- #include "diff.h"
-
- static long lastInode;
-
- int
- fstat (int fd, struct stat *theStat)
- {
- memset (theStat, 0, sizeof(*theStat));
- theStat->st_mode = 0 /*S_IFSTREAM*/;
- theStat->st_ito = ++lastInode;
- return (0);
- }
-
-
- int
- stat (xname, theStat)
- char *xname;
- register struct stat *theStat;
- {
- unsigned char name[256];
- int retval;
- CInfoPBRec info;
-
- strncpy ((char *)name, xname, 255);
- CtoPstr ((void *)name);
-
- memset (&info, 0, sizeof(info));
- retval = PBHGetVolSync ((WDPBPtr)&info);
- if ( ! errno )
- errno = retval;
- if ( retval )
- return (retval);
- info.hFileInfo.ioNamePtr = name;
- retval = PBGetCatInfoSync (&info);
- if ( ! errno )
- errno = retval;
-
- theStat->st_mtime = info.hFileInfo.ioFlMdDat;
- theStat->st_size = info.hFileInfo.ioFlLgLen;
- if ( info.hFileInfo.ioFlAttrib & ioDirMask )
- {
- theStat->st_mode = S_IFDIR;
- }
- else
- {
- theStat->st_mode = S_IFREG;
- }
- theStat->st_ito = ++lastInode;
- return (retval);
- }
-
- #ifdef NOTDEF
- /*
- ** due to difference of opinion btw gnu and microsoft about what
- ** const means, const is defined away in diff.h, which causes warnings
- ** when compiling the headers. This ugliness is avoided here.
- */
- #ifdef const
- #undef const
- #endif
- #include <string.h>
-
- DIR *
- opendir(char *name) {
- unsigned char localname[65];
- CInfoPBRec info;
- int errorReturned;
- DIR *rval;
-
- strcpy((char *)localname,name);
- CtoPstr ((void *)localname);
- memset (&info, 0, sizeof(info));
- errorReturned = PBHGetVolSync ((WDPBPtr)&info);
- if ( ! errno )
- errno = errorReturned;
- if ( errorReturned )
- return (NULL);
- info.dirInfo.ioNamePtr = localname;
- errorReturned = PBGetCatInfoSync (&info);
- if ( ! errno )
- errno = errorReturned;
- if ( errorReturned )
- return (NULL);
- rval = (void *)NewPtrClear((long)sizeof(DIR));
- rval->vRefNum = info.dirInfo.ioVRefNum;
- rval->dirID = info.dirInfo.ioDrDirID;
- rval->totalCount = info.dirInfo.ioDrNmFls;
-
- return rval;
- }
-
- void
- closedir(DIR *x) {
- free(x);
- }
-
- struct direct *
- readdir(DIR *thisdir) {
- int errorReturned;
-
- /*
- ** first time through, we don't need to look for a file
- */
- CInfoPBRec info;
-
- if ( thisdir->currCount >= thisdir->totalCount )
- return (NULL);
- memset (&info, 0, sizeof(info));
- thisdir->current.d_name[0] = 0;
- info.hFileInfo.ioNamePtr = (unsigned char *)&thisdir->current.d_name;
- info.hFileInfo.ioVRefNum = thisdir->vRefNum;
- info.hFileInfo.ioDirID = thisdir->dirID;
- info.hFileInfo.ioFDirIndex = thisdir->currCount + 1;
- errorReturned = PBGetCatInfoSync (&info);
-
- if ( ! errno )
- errno = errorReturned;
- if ( errorReturned )
- return (NULL);
-
- PtoCstr ((void *)&thisdir->current.d_name);
- thisdir->currCount++;
- return &thisdir->current;
- }
- #endif NOTDEF
-